import sys
from PyQt6.QtWidgets import QApplication,QWidget

class MainWindow(QWidget):#继承QWidget
    def __init__(self, *args, **kwargs):#self is default parameter;you can add other parameters;
        #*args is mean any parameters; *kwargs is mean any dictronary parameters;
        super().__init__()#继承执行父类的构造函数
        self.setWindowTitle("Hello World") #set window title;be overrides the title

        bg_color = kwargs.get('setbackgroundColor', None)
        if bg_color:
            self.setStyleSheet(f"background-color: {bg_color};")
        self.show()

if __name__ == "__main__":
    app=QApplication([])#创建一个应用  #Widgets是小控件的意思
    w=MainWindow(setbackgroundColor="lightblue") #use MainWindow created a window.
    w.setWindowTitle("Hello World2")
    w.show()#显示窗口
    app.exec()#运行程序
# app=QApplication([])
# window=QWidget(windowTitle="Hello World",)#创建一个窗口
# window.show()#显示窗口
# app.exec()#运行程序
